package com.cxyd.common.interceptor;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 *
 * 唯一码生成器 月日 + 4 位 随机 36 进制字符串
 */
public class UniqueCodeGenerator {

    private static final String CHARS = "23456789ABCDEFGHJKMNPQRSTUVWXYZ"; // 36 characters
    private static final int SUFFIX_LENGTH = 4;
    private static final Random RANDOM = new Random();

    public static String generateCode() {
        // 前4位：月日
        String mmdd = LocalDate.now().format(DateTimeFormatter.ofPattern("MMdd"));
        
        // 后4位：随机36进制字符串
        StringBuilder suffix = new StringBuilder();
        for (int i = 0; i < SUFFIX_LENGTH; i++) {
            suffix.append(CHARS.charAt(RANDOM.nextInt(CHARS.length())));
        }
        
        return mmdd + suffix.toString();
    }

    // 测试
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            System.out.println(generateCode());
        }
    }
}